EditResource = function() {
	return {
		/**
		 * 初始化省、市、区/县信息.
		 */
		initAreaField : function() {
			var districtId = $("#districtId_hidden").val();
			var cityId = $("#cityId_hidden").val();
			var provinceId = $("#provinceId_hidden").val();
			$('#province').combobox({
				url           : '/pc/provinces/getProvinces.htm',
				valueField    : "id",
				textField     : "province",
				editable      : false,
				required      : true,
				panelHeight   : 250,
				onLoadSuccess : function() {
					$('#province').combobox("setValue", provinceId);
				},
				onSelect      : function(value) {
					EditResource.cityCombobox(value.id, "");
					EditResource.areaCombobox("", "");
				}
			});
			EditResource.cityCombobox(provinceId, cityId);
			EditResource.areaCombobox(cityId, districtId);
		},
		
		cityCombobox : function(provinceId, cityId) {
			$('#city').combobox({
				url           : '/pc/cities/getCities.htm?provinceId=' + provinceId,
				valueField    : 'id',
				textField     : 'city',
				editable      : false,
				required      : true,
				panelHeight   : 250,
				onLoadSuccess : function() {
					$('#city').combobox("setValue", cityId);
				},
				onSelect      : function(value) {
					EditResource.areaCombobox(value.id, "");
				}
			});
		},
		
		areaCombobox : function(cityId, districtId) {
			$('#district').combobox({
				url         : '/pc/areas/getAreas.htm?cityId=' + cityId,
				valueField  : 'id',
				textField   : 'area',
				editable    : false,
				panelHeight : 250,
				onLoadSuccess : function() {
					$('#district').combobox("setValue", districtId);
				}
			});
		},
		
		/**
		 * 初始化频道、行业、服务项目信息.
		 */
		initServiceField : function() {
			var channelId = $("#channelId_hidden").val();
			var industryId = $("#industryId_hidden").val();
			var serviceItemId = $("#serviceItemId_hidden").val();
			$('#channel').combobox({
				url           : '/pc/channel/channels.htm',
				valueField    : "channelId",
				textField     : "channelName",
				editable      : false,
				required      : true,
				panelHeight   : 'auto',
				onLoadSuccess : function() {
					$('#channel').combobox("setValue", channelId);
				},
				onSelect      : function(value) {
					EditResource.industryCombobox(value.channelId, "");
					EditResource.serviceItemCombobox("", "");
				}
			});
			EditResource.industryCombobox(channelId, industryId);
			EditResource.serviceItemCombobox(industryId, serviceItemId);
		},
		
		industryCombobox : function(channelId, industryId) {
			$('#industry').combobox({
				url           : '/pc/industry/industrys.htm?channelId=' + channelId,
				valueField    : "industryId",
				textField     : "industryName",
				editable      : false,
				required      : true,
				panelHeight   : 200,
				onLoadSuccess : function() {
					$('#industry').combobox("setValue", industryId);
				},
				onSelect      : function(value) {
					EditResource.serviceItemCombobox(value.industryId, "");
				}
			});
		},
		
		serviceItemCombobox : function(industryId, serviceItemId) {
			$('#serviceItem').combobox({
				url           : '/pc/serviceItem/serviceItems.htm?industryId=' + industryId,
				valueField    : "serviceItemId",
				textField     : "serviceItemName",
				editable      : false,
				required      : true,
				panelHeight   : 200,
				onLoadSuccess : function() {
					$('#serviceItem').combobox("setValue", serviceItemId);
				}
			});
		},
		
		/**
		 * 保存审核结果.
		 */
		saveApproveInfo : function() {
			var approveResult = $.trim($("#approveResult").val());
			if(null == approveResult || "" == approveResult) {
				Ict.warn("请选择审核结果!");
				return false;
			}
			var approveMsg = $.trim($("#approveMsg").val());
			if(null == approveMsg || "" == approveMsg) {
				Ict.warn("请填写审核意见!");
				return false;
			}
			var resourceId = $("#resourceId").val();
			$.ajax({
				url        : "/pc/resource/saveApprove.htm",
				type       : 'POST',
				data       : {
					"resourceId"       : resourceId,
					"approveResult"    : approveResult,
					"approveMsg"       : approveMsg
				},
				dataType   : 'JSON',
				async      : false,
				success    : function(data) {
					if("SUCCESS" == data) {
						Ict.info("提交审核成功！", function() {
							EditResource.goBack();
						});
					} else {
						Ict.info("提交审核失败！");
					}
				}
			});
		},
		
		/**
		 * 提交审核结果,并更新商户信息.
		 */
		commitModify : function() {
			var approveResult = $.trim($("#approveResult").val());
			if(null == approveResult || "" == approveResult) {
				Ict.warn("请选择审核结果!");
				return false;
			}
			var approveMsg = $.trim($("#approveMsg").val());
			if(null == approveMsg || "" == approveMsg) {
				Ict.warn("请填写审核意见!");
				return false;
			}
			var resourceId = $("#resourceId").val();
			var shopId = $("#shopId").val();
			var resourceName = $("#resourceName").val();
			var shortName = $("#shortName").val();
			var branchName = $("#branchName").val();
			var channelId = $('#channel').combobox("getValue");
			var industryId = $('#industry').combobox("getValue");
			var serviceItemId = $('#serviceItem').combobox("getValue");
			var telno = $("#telno").val();
			var districtId = $('#district').combobox("getValue");
			var cityId = $('#city').combobox("getValue");
			var provinceId = $('#province').combobox("getValue");
			var address = $("#address").val();
			var landmark = $("#landmark").val();
			var recommendation = $("#recommendation").val();
			var specialOffer = $("#specialOffer").val();
			var feature = $('#feature').combobox('getText');
			var tag = $("#tag").val();
			var region = $("#region").val();
			var openTime = $("#openTime").val();
			var busRoute = $("#busRoute").val();
			var route = $("#route").val();
			var chargeType = $("#chargeType").val();
			var cost = $("#cost").val();
			var privateRoom = $("#privateRoom").val();
			var reservation = $("#reservation").val();
			var deliveryService = $("#deliveryService").val();
			var mobilePayment = $("#mobilePayment").val();
			var parking = $("#parking").val();
			var zipcode = $("#zipcode").val();
			var ticketPrice = $("#ticketPrice").val();
			var introduction = $("#introduction").val();
			var area = $("#area").val();
			var x = $("#x").val();
			var y = $("#y").val();
			var isOutbound = $("#isOutbound").val();
			var capacity = $("#capacity").val();
			var maxCapacity = $("#maxCapacity").val();
			var minCapacity = $("#minCapacity").val();
			var officialSite = $("#officialSite").val();
			var infoMaintain = $("#infoMaintain").val();
			var addMan = $("#addMan").val();
			var addDate = $("#addDate").val();
			var approveResult = $("#approveResult").val();
			var approveMsg = $("#approveMsg").val();
			$.ajax({
				url  : basePath + "/pc/resource/update.htm",
				type : 'POST',
				data : {
					"resourceId"       : resourceId,
					"shopId"           : shopId,
					"resourceName"     : resourceName,
					"shortName"        : shortName,
					"branchName"       : branchName,
					"channelId"        : channelId,
					"industryId"       : industryId,
					"serviceItemId"    : serviceItemId,
					"telno"            : telno,
					"districtId"       : districtId,
					"cityId"           : cityId,
					"provinceId"       : provinceId,
					"address"          : address,
					"landmark"         : landmark,
					"recommendation"   : recommendation,
					"specialOffer"     : specialOffer,
					"feature"          : feature,
					"tag"              : tag,
					"region"           : region,
					"openTime"         : openTime,
					"busRoute"         : busRoute,
					"route"            : route,
					"chargeType"       : chargeType,
					"cost"             : cost,
					"privateRoom"      : privateRoom,
					"reservation"      : reservation,
					"deliveryService"  : deliveryService,
					"mobilePayment"    : mobilePayment,
					"parking"          : parking,
					"zipcode"          : zipcode,
					"ticketPrice"      : ticketPrice,
					"introduction"     : introduction,
					"area"             : area,
					"x"                : x,
					"y"                : y,
					"isOutbound"       : isOutbound,
					"capacity"         : capacity,
					"maxCapacity"      : maxCapacity,
					"minCapacity"      : minCapacity,
					"officialSite"     : officialSite,
					"infoMaintain"     : infoMaintain,
					"addMan"           : addMan,
					"addDate"          : addDate,
					"approveResult"    : approveResult,
					"approveMsg"       : approveMsg
				},
				dataType   : 'JSON',
				async      : false,
				success    : function(data) {
					var json = $.parseJSON(data);
					if(json.status == '1') {
						Ict.info("更新成功！", function() {
							EditResource.goBack();
						});
					} else {
						var messages = "";
						var resultList = eval(json.result);
						for(var i = 0;i < resultList.length; i++) {
							messages += resultList[i].message + ",";
						}
						messages = messages.substring(0, messages.length - 1);
						Ict.error("更新失败！" + messages);
					}
				}
			});
		},
		
		closeTab : function() {
			window.parent.Ict.closeSelectedTab();
		},
		
		goBack : function() {
			window.location.href = "/pc/resource/main.htm";
		},
		
		selectTags : function() {
			Ict.openWin("选择标签", 350, 400, "/pc/tag/selectTags.htm");
		}
	};
}();

$(function(){
	EditResource.initAreaField();
	EditResource.initServiceField();
});